import json
import os
import random
import threading

from Fruit import Fruit
import requests

class Hello:

    @staticmethod
    def file_write():
        # 文件写入
        context = "hello, world"
        f = open("X:/workspace/hello_python/file/Hello.txt", 'w')
        f.write(context)
        # os.remove('X:/workspace/hello_python/file/Hello.txt')
        f.close()

    @staticmethod
    def file_read():
        f = open("hello.txt")
        print(str(f.read().strip()))

    @staticmethod
    def range():
        for x in range(0, 5):
            print(x)

    @staticmethod
    def tuple_test():
        # 元组
        tuple_name = ("apple", "banana", "grape", "orange")
        # 列表 list
        tuple_list = ["apple", "banana", "grape", "orange"]
        print(tuple_list[1][0:9])
        # 字典
        dict = {"a": "apple", "b": "banana", "g": "grage", "o": "orange"}

    @staticmethod
    def clase_create():
        # 类创建
        fruit = Fruit()
        fruit.grow()

    # 定义函数
    @staticmethod
    def arithmetic(x, y, operator = "+"):
        result = {
            "+": x + y,
            "-": x - y,
            "*": x * y,
            "/": x / y
        }
        return result.pop(operator);

    @staticmethod
    def testStrformat():
        accessToken = 'sdfdsfdsfdsfdsfd'
        headers = {'Authorization': accessToken}
        print(headers)

    @staticmethod
    def testDicForeach():
        workDataList = []
        workData = {'2023-03-01': 8, '2023-03-02': 8}
        for key, value in workData.items():
            # print(key + ': ' + str(value))
            temp = {key: value}
            workDataList.append(temp)

        print(workDataList)

        for item in workDataList:
            for key in item.keys():
                print(key)
                print(item.get(key))

    @staticmethod
    def testRandom(a, b):
        batchId = random.randint(a, b)
        print(batchId)

    def testUploadIsOver(batchId):
        response = requests.get("http://10.3.9.55:12333/file/transfer/log?operatorType=UPLOAD_UPDATE_JAR&batchId="+batchId)
        responseJson = json.loads(response.text)

        statusList = []
        for item in responseJson.get("data"):
            statusList.append(item["status"])
        statusList = list(set(statusList))
        if len(statusList) > 1:
            return batchId.testUploadIsOver(batchId)
        else:
            print("文件上传完成")
            return True



if __name__ == '__main__':
    # Hello.clase_create()
    # result = Hello.arithmetic(y = 5, x = 2, operator = "-")
    # result1 = Hello.arithmetic(y = 5, x = 2)
    # print(result)
    # print(result1)

    # 键盘输入
    # str = input()
    # print("你输入的内容是: ", str)

    # 测试字符填充
    # Hello.testStrformat()

    # 字典遍历
    # Hello.testDicForeach()

    # 读取
    # Hello.file_read()

    # 随机数
    # Hello.testRandom(1686042429427, 1686099999999)

    # 上传是否完成
    # testUploadIsOver(1686042429427)
    # dic = {"a" : 1}
    # if bool(dic):
    #     print("非空")
    # else:
    #     print("空")

    original_str = 'dfbp-biz-offlineipo-V2.24.1.1.11_3-RELEASE.jar'.replace('.jar', '')

    # 分割字符串
    parts = original_str.split('-V')

    # 提取第一部分
    first_part = parts[0]

    # 提取第二部分
    version_part = parts[1]

    print("第一部分:", first_part)
    print("版本部分:", version_part)
